<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="肩套名称" prop="neckRingName">
      <el-input v-model="dataForm.neckRingName" placeholder="肩套名称"></el-input>
    </el-form-item>
    <el-form-item label="肩套型号" prop="neckRingNo">
      <el-input v-model="dataForm.neckRingNo" placeholder="肩套型号"></el-input>
    </el-form-item>
    <el-form-item label="规格描述" prop="neckRingDesc">
      <el-input v-model="dataForm.neckRingDesc" placeholder="规格描述"></el-input>
    </el-form-item>
    <el-form-item label="肩套类别" prop="neckRingType">
      <el-input v-model="dataForm.neckRingType" placeholder="肩套类别"></el-input>
    </el-form-item>
    <el-form-item label="肩套口径" prop="bottleOutDiameter">
      <el-input v-model="dataForm.bottleOutDiameter" placeholder="肩套口径"></el-input>
    </el-form-item>
    <el-form-item label="肩套颜色" prop="neckRingColor">
      <el-input v-model="dataForm.neckRingColor" placeholder="肩套颜色"></el-input>
    </el-form-item>
    <el-form-item label="肩套的材质" prop="neckRingMaterial">
      <el-input v-model="dataForm.neckRingMaterial" placeholder="肩套的材质"></el-input>
    </el-form-item>
    <el-form-item label="等级，A级。B级" prop="relateRingLevel">
      <el-input v-model="dataForm.relateRingLevel" placeholder="等级，A级。B级"></el-input>
    </el-form-item>
    <el-form-item label="图片信息" prop="relateImageInfo">
      <el-input v-model="dataForm.relateImageInfo" placeholder="图片信息"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          neckRingName: '',
          neckRingNo: '',
          neckRingDesc: '',
          neckRingType: '',
          bottleOutDiameter: '',
          neckRingColor: '',
          neckRingMaterial: '',
          relateRingLevel: '',
          relateImageInfo: '',
          remark: '',
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: '',
          parentId: ''
        },
        // dataRule: {
        //   neckRingName: [
        //     { required: true, message: '肩套名称不能为空', trigger: 'blur' }
        //   ],
        //   neckRingNo: [
        //     { required: true, message: '肩套型号不能为空', trigger: 'blur' }
        //   ],
        //   neckRingDesc: [
        //     { required: true, message: '规格描述不能为空', trigger: 'blur' }
        //   ],
        //   neckRingType: [
        //     { required: true, message: '肩套类别不能为空', trigger: 'blur' }
        //   ],
        //   bottleOutDiameter: [
        //     { required: true, message: '肩套口径不能为空', trigger: 'blur' }
        //   ],
        //   neckRingColor: [
        //     { required: true, message: '肩套颜色不能为空', trigger: 'blur' }
        //   ],
        //   neckRingMaterial: [
        //     { required: true, message: '肩套的材质不能为空', trigger: 'blur' }
        //   ],
        //   relateRingLevel: [
        //     { required: true, message: '等级，A级。B级不能为空', trigger: 'blur' }
        //   ],
        //   relateImageInfo: [
        //     { required: true, message: '图片信息不能为空', trigger: 'blur' }
        //   ],
        //   remark: [
        //     { required: true, message: '备注不能为空', trigger: 'blur' }
        //   ],
        //   createUser: [
        //     { required: true, message: '创建者不能为空', trigger: 'blur' }
        //   ],
        //   createTime: [
        //     { required: true, message: '创建时间不能为空', trigger: 'blur' }
        //   ],
        //   updateUser: [
        //     { required: true, message: '更新者不能为空', trigger: 'blur' }
        //   ],
        //   updateTime: [
        //     { required: true, message: '更新时间不能为空', trigger: 'blur' }
        //   ],
        //   parentId: [
        //     { required: true, message: '父级不能为空', trigger: 'blur' }
        //   ]
        // }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relateneckringinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.neckRingName = data.relateNeckRingInfo.neckRingName
                this.dataForm.neckRingNo = data.relateNeckRingInfo.neckRingNo
                this.dataForm.neckRingDesc = data.relateNeckRingInfo.neckRingDesc
                this.dataForm.neckRingType = data.relateNeckRingInfo.neckRingType
                this.dataForm.bottleOutDiameter = data.relateNeckRingInfo.bottleOutDiameter
                this.dataForm.neckRingColor = data.relateNeckRingInfo.neckRingColor
                this.dataForm.neckRingMaterial = data.relateNeckRingInfo.neckRingMaterial
                this.dataForm.relateRingLevel = data.relateNeckRingInfo.relateRingLevel
                this.dataForm.relateImageInfo = data.relateNeckRingInfo.relateImageInfo
                this.dataForm.remark = data.relateNeckRingInfo.remark
                this.dataForm.createUser = data.relateNeckRingInfo.createUser
                this.dataForm.createTime = data.relateNeckRingInfo.createTime
                this.dataForm.updateUser = data.relateNeckRingInfo.updateUser
                this.dataForm.updateTime = data.relateNeckRingInfo.updateTime
                this.dataForm.parentId = data.relateNeckRingInfo.parentId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relateneckringinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'neckRingName': this.dataForm.neckRingName,
                'neckRingNo': this.dataForm.neckRingNo,
                'neckRingDesc': this.dataForm.neckRingDesc,
                'neckRingType': this.dataForm.neckRingType,
                'bottleOutDiameter': this.dataForm.bottleOutDiameter,
                'neckRingColor': this.dataForm.neckRingColor,
                'neckRingMaterial': this.dataForm.neckRingMaterial,
                'relateRingLevel': this.dataForm.relateRingLevel,
                'relateImageInfo': this.dataForm.relateImageInfo,
                'remark': this.dataForm.remark,
                'createUser': this.dataForm.createUser,
                'createTime': this.dataForm.createTime,
                'updateUser': this.dataForm.updateUser,
                'updateTime': this.dataForm.updateTime,
                'parentId': this.dataForm.parentId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
